﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FrameWorkCore
{
    public static class SwaggerService
    {

 
        public static void ConfigureSwagger(this IServiceCollection services)
        {

            services.AddSwaggerGen(c =>
            {
                c.DocInclusionPredicate((docName, description) => true);//Swagger support dynamically generated API interface
                c.CustomSchemaIds(type => type.FullName);
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version = "v1",
                    Title = "LHR WebApi6 document",
                    Description = "LHR WebApi6",
                    Contact = new OpenApiContact
                    {
                        Name = "play with you",
                        Email = "1486971629@qq.com",
                    }
                });
                var xmlPath = Path.Combine(AppContext.BaseDirectory, "Entity.xml");
                var xmlPath1 = Path.Combine(AppContext.BaseDirectory, "WebApi6.xml");
                var xmlPath2 = Path.Combine(AppContext.BaseDirectory, "Application.xml");
                c.IncludeXmlComments(xmlPath, true);              
                c.IncludeXmlComments(xmlPath1, true);
                c.IncludeXmlComments(xmlPath2, true);
                c.AddSecurityDefinition("BearerAuth", new OpenApiSecurityScheme
                {
                    Scheme = "BearerAuth",
                    Description = "Jwt authorized (data will be transmitted in the request header) input below bearer token can, pay attention to the space between",
                    Name = "Authorization",
                    In = ParameterLocation.Header,
                    Type = SecuritySchemeType.ApiKey
                });
            });

        }
    }
}
